package com.sxkj.gis.wms.GetFeatureInfo.service.impl;

import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.ignite.Ignite;
import org.apache.ignite.Ignition;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.NoSuchAuthorityCodeException;
import org.springframework.stereotype.Service;
import com.sxkj.gis.wms.GetFeatureInfo.service.GetFeatureInfoService;
import com.sxkj.gis.wms.bean.DoWmsParams;
import com.sxkj.gis.wms.bean.WmsParams;
import com.sxkj.gis.wms.factory.DoWmsParamsFactory;
import com.sxkj.gis.wms.factory.WmsFactory;

@Service("getFeatureInfoService")
public class GetFeatureInfoServiceImpl implements GetFeatureInfoService {

	@Override
	public byte[] getFeatureInfoTextPlain(HttpSession session, HttpServletRequest rq, HttpServletResponse rp, WmsParams wmsParams) throws IOException, NoSuchAuthorityCodeException, FactoryException {
		boolean conn = (boolean) session.getAttribute("flog");
		WmsFactory wpf = new DoWmsParamsFactory();
		if (conn) {
			String igniteClientGridName = (String) session.getAttribute("clientGridName");
			Ignite ignite = Ignition.ignite(igniteClientGridName);
			System.out.println("--------->目前没有连接Ignite，所有返回为null;");
			return null;
		} else {
			DoWmsParams dwp = wpf.createDoWmsParamsGetFeatureInfo(wmsParams);
			// getMap由客户端自行处理，并放回
			dwp.getFeatureInfoRequest();
			byte[]  out = dwp.getFeatureInfoRequest().get("textStream");
			
			
			return out;
		}
	}

}
